package example.telosys.persistence;

import java.util.List;

import org.telosys.persistence.PersistenceManager;
import org.telosys.persistence.PersistenceManagerFactory;
import org.telosys.persistence.TelosysPersistence;

public class FindAll {

	protected PersistenceManager pm ; 

	public FindAll() {
		super();
		PersistenceManagerFactory pmf = TelosysPersistence.getPersistenceManagerFactory();
		this.pm = pmf.createPersistenceManager();
		System.out.println("--- pm ready");
		System.out.println("pm.isOpen() : " + pm.isOpen() );
		System.out.println("pm.isAutoCommitMode() : " + pm.isAutoCommitMode() );
	}
	
	public void listAll(Class<?> entityClass) 
	{
		List<?> list = pm.loadAll(entityClass);
		for ( Object o : list ) {
			System.out.println(" . " + o );
		}
	}
	
	public void close() 
	{
		System.out.println("--- close pm");
		System.out.println("pm.isOpen() : " + pm.isOpen() );
		pm.close();
		System.out.println("pm.isOpen() : " + pm.isOpen() );
	}
}
